#!/bin/bash
#-Xms: 设置初始化堆内存大小；
#-Xmx: 设置最大可分配堆内存大小
#MetaspaceSize:元空间默认大小
#MaxMetaspaceSize:元空间最大大小
#JVM参数

JVM_OPTS="-Xms256m -XX:MetaspaceSize=256M -Xmx256m -XX:MaxMetaspaceSize=512M -Dfile.encoding=utf-8"
LOG_HOME="/home/logs/"
SERVER_NAME="violet-gateway"
#TODAY=$(date -d "now" +"%Y-%m-%d")
LOG_FILE="/com.northmeter-info.log"
LOG_PATH=${LOG_HOME}${SERVER_NAME}${LOG_FILE}
#ACTIVE="test"
#脚本绝对路径
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
LIB_PATH="${SCRIPT_DIR}/lib"
#杀死已有进程
echo stop ${SERVER_NAME} ..
PID=$(ps -ef | grep ${SERVER_NAME}.jar | grep -v grep | awk '{print $2}')

if [ ! $PID ]; then
    echo "process ${SERVER_NAME} not exit"
else
    echo "process id: $PID"
kill -9 ${PID}

  if [ $? -eq 0 ]; then
    echo "stop ${SERVER_NAME} success"
  else
    exit
  fi
fi
#重启

echo start ${SERVER_NAME} ..
nohup java ${JVM_OPTS} -jar >/dev/null 2>&1 & tail -f ${LOG_PATH}
#指定配置文件环境启动
# nohup java ${JVM_OPTS} -Dspring.profiles.active=${ACTIVE} -jar -Dloader.path=${LIB_PATH} ${JAR_PATH} >/dev/null 2>&1 & tail -f ${LOG_PATH}

echo 'start successful'


# java -Xms256m -XX:MetaspaceSize=256M -Xmx256m -XX:MaxMetaspaceSize=512M --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.math=ALL-UNNAMED -Dfile.encoding=utf-8 -jar violet-uaa.jar
